//
//  OSHeader.swift
//  OurSwift
//
//  Created by PushMeBaby on 16/1/1.
//  Copyright © 2016年 MMM. All rights reserved.
//

import Foundation
import UIKit


let OSScreenW = UIScreen.mainScreen().bounds.width
let OSScreenH = UIScreen.mainScreen().bounds.height
let OSCellMargin:CGFloat = 10.0
let OSMargin:CGFloat = 15.0
func OSColor (red : CGFloat , green : CGFloat , blue : CGFloat ) -> UIColor{
    
    let color =  UIColor.init(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: 1)
    
    return color
    
}
let OSTitleColor = OSColor(0,green: 171,blue: 235)
let OSDarkGrayColor = OSColor(138, green: 138, blue: 138)
let OSGrayColor = OSColor(237,green: 237,blue: 237)
let OSBackGroundColor = OSColor(239,green: 239,blue: 244)
let OSColor535353 = OSColor(83,green: 83,blue: 83)
let OSRandomColor = OSColor(CGFloat(random() % 255) , green:  CGFloat(random() % 255) , blue: CGFloat(random() % 255) )
let OSColor4F4F4F = OSColor(79,green: 79,blue: 79)
let OSColorD2D2D2 = OSColor(210,green: 210,blue: 210)
let OSTitleLabelColor = OSColor(83,green: 83,blue: 83)
enum OSDateProgressNodeViewStyle{
    case Finish
    case Proceed
    case NotComplete
}
func OSAttributedParagraphLineSpacingTool(addressText:(String), lineSpacing: (CGFloat), font: (UIFont)) ->NSAttributedString{
    let attributedString = NSMutableAttributedString(string: addressText)
    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineSpacing = lineSpacing
    attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, addressText.characters.count))
    attributedString.addAttribute(NSFontAttributeName, value: font, range:  NSMakeRange(0, addressText.characters.count))
    return attributedString
}
func OSGetAttributedStringHeightTool(text: String, font: UIFont, let size: CGSize,lineSpacing: (CGFloat)) ->CGFloat{
    let attributedString = OSAttributedParagraphLineSpacingTool(text, lineSpacing: lineSpacing, font: font)
    let actualSize =  attributedString.boundingRectWithSize(size, options: NSStringDrawingOptions.UsesLineFragmentOrigin , context: nil)
    return actualSize.height
}
func OSGetTextHeightTool(text:String, font:UIFont, var size: CGSize) ->CGFloat{
    if(size == CGSizeZero){
        size = CGSizeMake(UIScreen.mainScreen().bounds.width-50, 999)
    }
    let dic = NSDictionary(object: font, forKey: NSFontAttributeName)
    let actualSize = text.boundingRectWithSize(size, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: dic as? [String : AnyObject], context: nil)
    return actualSize.height
}
func ImageViewColor(color: UIColor) -> UIImage{
    let rect = CGRectMake(0, 0, 1, 1)
    UIGraphicsBeginImageContext(rect.size)
    let context =  UIGraphicsGetCurrentContext()
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    let image =  UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image
}
struct OSNominate {
    let title: String
    let detail: String
    var heigth: CGFloat{
        get{
            let  detailHeight = OSGetAttributedStringHeightTool(detail, font: UIFont.systemFontOfSize(12), size: CGSizeMake(OSScreenW - 50, 999), lineSpacing: 7)
            return  detailHeight + 72
        }
    }
}

struct OSTextHeight {
    let text: String
    var height: CGFloat {
        get{
            let  detailHeight = OSGetAttributedStringHeightTool(text, font: UIFont.systemFontOfSize(13), size: CGSizeMake(OSScreenW - 50, 999), lineSpacing: 10)
            return  detailHeight + 1
        }
    }
}





